<extend name="Public/main" />

<block name="body">
	<div class="wrap J_check_wrap">
		<div class="nav">
			<ul class="cc">
				<li class="current"><a href="{:U('Recipients/apply')}">申请列表</a></li>
				<li class=""><a href="{:U('Excel/publishOld')}" target="_blank">导入【旧版】</a></li>
				<li class=""><a href="{:U('Excel/publishNew')}" target="_blank">导入【新版】</a></li>
				<!-- <li><a href="{:U('Recipients/addeteacher')}">添加老师</a></li> -->
			</ul>
		</div>
		<div class="h_a" style="background:#fff;">
				<form  method="post">
				<div class="search_type cc mb10">
				<p>
				<span style="padding-right:10px;">审核状态：</span>
				<a class="fa  <?php if(!isset($_GET['status'])||$_GET['status']=="null"){echo "fa-check-square"; }else{echo "fa-square";} ?>" href="?&all=all"><span style="padding-left:3px;">全部</span></a> <span style="padding-left:5px;"></span>
					<?php foreach (C('RECIPIENTS_STAUES') as $key => $v): ?>
						<a class="fa  <?php if(isset($_GET['status'])&&$_GET['status']==$key){echo "fa-check-square"; }else{echo "fa-square";} ?>" href="?&status={$key}"><span style="padding-left:3px;">{$v}</span></a> <span style="padding-left:5px;"></span>
					<?php endforeach ?>
				
				</p>

				<!-- <p>
				<span style="padding-right:10px;">走访状态：</span>
					<?php foreach (C('RECIPIENTS_STAUES') as $key => $v): ?>
						<span style="padding-right:3px;">{$v}</span><a class="fa fa-square"></a> <span style="padding-left:5px;"></span>
					<?php endforeach ?>
				
				</p> -->
					

				</div>
			</form>

		</div>
	
		<form class="J_ajaxForm" action="{:U('Menu/listorders')}" method="post">
			<div class="table_list">
				<table width="100%">
					
					<thead>
						<tr>
							<td><a href="javascript:;" class="checkall">全选</a>/<a href="javascript:;" class="checkfan">反选</a></td>
							
								
								
							<script type="text/javascript">
							$('.checkall').click(function(event) {
								hd_select_all('.J_ajaxForm');
							});
							$('.checkfan').click(function(event) {
								hd_reverse_select('.J_ajaxForm')
							});
							</script>
							<td>ID</td>
							<td>申请人</td>
							<td>申请人电话</td>
							<td>申请人邮箱</td>
							<td>学生姓名</td>
							<td>走访状态 <i class="fa fa-hand-o-up"></i></td>
							<td>状态 <i class="fa fa-hand-o-up"></i></td>
							<td>管理操作</td>
							
						</tr>
					</thead>
					<tbody>
					<?php foreach ($applyArr as $key => $v): ?>
						<tr>
						<td><input type="checkbox" applyid="{$v.id}" status="{$v['status']}" name="choose"></td>
							
							<td>{$v.id}</td>
							<td>{$v.apply_name}</td>
							<td>{$v.apply_phone}</td>
							<td>{$v.apply_email}</td>
							<td>{$v.student_name}</td>
							<td>
								<?php if($v['vlCount']!=0){ ?>
								<a href="javascript:;" class="btn btn_success vlrest-btn-a"><i class="fa fa-meh-o"></i><span style="padding-left:10px;"></span>共（{$v.vlCount}）条反馈</a>

								<?php }else{ ?>
								<a href="javascript:;" class="fa fa-frown-o btn vlrest-btn-a">未反馈</a>
								<?php } ?>
								
								<select name="" id="" style="display:none" class="vlRest-btn btn">
									<option value="" class="sub-vlre" onclick="window.open('{:U('Recipients/vlRequest',array('id'=>$v['id']))}')">提交反馈</option>
									<option value="" class="check-vlre" onclick="window.open('{:U('Recipients/vlRequestList',array('id'=>$v['id']))}')">查看反馈</option>
								</select>
								
							</td>
							<script type="text/javascript">
							$('.vlrest-btn-a').click(function(event) {
								$(this).hide();
								$(this).siblings('.vlRest-btn').show();
							
							});
						
							</script>
							<td> 
							<?php $status = C('RECIPIENTS_STAUES'); ?>
							<?php if($v['status']<0){ ?>
								<p  class="btn hd-btn-danger statues-btn">暂停中 </p> 
							<?php }else{ ?>
								<p  class="btn statues-btn hd-btn-success"><?php   echo $status[$v['status']];  ?> </p> 
							<?php } ?>
								<select name="" class="btn change-statues"  delid = "{$v.id}" style="display:none;">
									<?php foreach (C('RECIPIENTS_STAUES') as $ki => $vi): ?>
										<option value="{$ki}">{$vi}</option>
									<?php endforeach ?>
									<!-- <option value="-1">暂停</option> -->
								</select>
								<input type="hidden" name="staus" value="{$v.status}" class="status">
								</td>
							<td>
						
								<a href="{:U('Recipients/applyDetail',array('id'=>$v['id']))}" target="_blank" class="btn">查看</a>
								<a href="{:U('Recipients/chart',array('id'=>$v['id']))}" target="_blank" class="btn">图表信息</a>
								<!-- <a href="{:U('Recipients/sendmail',array('id'=>$v['id']))}" class="btn">发送邮件</a>  -->
								<a href="{:U('Recipients/editApply',array('id'=>$v['id']))}" class="btn">修改</a>
								<!-- //发起资助后，不可以删除 -->
								<input type="hidden" name="staus" value="{$v.status}" class="status">
								<?php if($v['status']==3){ ?>
								<!-- <a href="javascript:;" class="btn btn_sublimt Update-row" delid = "{$v.id}">同步前台数据</a> -->
								<?php }else{ ?>
								<a href="javascript:;" class="btn btn_error del-row" delid = "{$v.id}">删除</a>
								<?php } ?>
								
								<a href="{:U('Excel/pullbyexcel',array('id'=>$v['id']))}" class="mr5 btn">导出Excel</a>
							</td>
						</tr>
						
					<?php endforeach ?>
						<thead>
						<tr>
							<td><a href="javascript:;" class="checkall">全选</a>/<a href="javascript:;" class="checkfan">反选</a></td>
							
								
								
							<script type="text/javascript">
							$('.checkall').click(function(event) {
								hd_select_all('.J_ajaxForm');
							});
							$('.checkfan').click(function(event) {
								hd_reverse_select('.J_ajaxForm')
							});
							</script>
							<td>ID</td>
							<td>申请人</td>
							<td>申请人电话</td>
							<td>申请人邮箱</td>
							<td>学生姓名</td>
							<td>走访状态 <i class="fa fa-hand-o-up"></i></td>
							<td>状态 <i class="fa fa-hand-o-up"></i></td>
							<td>管理操作</td>
							
						</tr>
					</thead>
					</tbody>
				</table>

				<script type="text/javascript">
				//同步数据
				$('.Update-row').click(function(event) {
					var id = $(this).attr('delid');
					$.ajax({
						url: '{:U('Ajax/Apply/ajaxAppUpRe')}',
						type: 'post',
						dataType: 'html',
						data: {id: id},
						success:function(d){
							layer.open({
							    type: 2,
							    area: ['700px', '530px'],
							    fix: false, //不固定
							    maxmin: true,
							    content: d
							});

						}
					})
				
					
				});
				//删除申请
				$('.del-row').click(function(event) {
					var status = $(this).siblings('.status').val();
					if(status==3){
						cmzAlert('此申请已完结，不可删除',2);
						return false;
					}
					if(!confirm('确定删除吗？')){return false}
						var id = $(this).attr('delid');
						$.ajax({
							url: '{:U('Ajax/Apply/ajaxDelApply')}',
							type: 'post',
							dataType: 'html',
							data: {id: id},
							success:function(){
								location.reload()
							}
						})
						
						
				});
				$('.statues-btn').click(function(event) {
					$(this).hide()
					$(this).siblings('.change-statues').show();
					
				});
				//更改状态
				$('.change-statues').change(function(event) {
					var status = $(this).siblings('.status').val();
					// alert(status);
					if(status==3){
						cmzAlert('此申请已完结，不可更改状态',2);
						return false;
					}
					if(!confirm('确定要更改申请单状态吗？')){return false}
					var status = $(this).val();
					var id = $(this).attr('delid');
					$.ajax({
							url: '{:U('Ajax/Apply/AjaxCkStatues')}',
							type: 'post',
							dataType: 'html',
							data: {id: id,status:status},
							success:function(){
								location.reload()
							}
						})

				
				});
				</script>
				<div class="p10"><div class="pages"> {$Page} </div> </div>

			</div>
			<div class="">
				<div class="btn_wrap_pd">             
					<a class="btn btn_submit mr10 J_ajax_submit_btn J_delete" href="javascript:;">批量删除</a>
					<a class="btn btn_submit mr10 J_ajax_submit_btn J_changestatues" href="javascript:;">批量更改状态</a>
					<select name="" class="btn J_changestatues_select"  delid = "{$v.id}" style="display:none;">
						<?php foreach (C('RECIPIENTS_STAUES') as $k => $v): ?>
							<option value="{$k}">{$v}</option>
						<?php endforeach ?>
					
					</select>
					<script type="text/javascript">
					//指删除
					$('.J_delete').click(function(event) {
						if(!confirm('确定要删除申请单状态吗？')){return false}
						  var ids = "";
						
						$('input:checkbox[name=choose]:checked').each(function(index, el) {
							var status = $('input:checkbox[name=choose]:checked').eq(index).attr('status');
							//发起资助的小孩不可以删除
							id= $('input:checkbox[name=choose]:checked').eq(index).attr('applyid');
							 ids +=id;
							 ids+=",";
						});
						if(ids==""||!ids){
							cmzAlert('请先选择要删除的数据',2);
							return false;
						}
						$.ajax({
							url: "{:U('Ajax/Apply/moreDelApply')}",
							type: 'post',
							dataType: 'html',
							data: {id: ids},
							success:function(d){
								if(d){
									$('input:checkbox[name=choose]').removeAttr('checked');
									window.location.reload();
								}
							}
						})
					
					});
					//指更改状态
					$('.J_changestatues').click(function(event) {
						$(this).hide();
						$('.J_changestatues_select').show();
						 
					});
					$('.J_changestatues_select').change(function(event) {
						 var ids = "";
						 var status = $(this).val();
						 // alert(status);
						 // alert($('input:checkbox[name=choose]:checked').length)
						$('input:checkbox[name=choose]:checked').each(function(index, el) {
							id= $('input:checkbox[name=choose]:checked').eq(index).attr('applyid');
							 ids +=id;
							 ids+=",";
						});
						if(ids==""||!ids){
							cmzAlert('请先选择要修改的数据',2);
							return false;
						}
						$.ajax({
							url: "{:U('Ajax/Apply/moreChangeStates')}",
							type: 'post',
							dataType: 'html',
							data: {id: ids,status:status},
							success:function(d){
								if(d){
									$('input:checkbox[name=choose]').removeAttr('checked');
									window.location.reload();
								}
							}
						})
					
					});
						

					</script>
					<!-- <button class="btn btn_submit mr10 J_ajax_submit_btn" type="submit">同步前台</button> -->
					<!-- <button class="btn btn_submit mr10 J_ajax_submit_btn" type="submit">导出EXCEL</button> -->
					<!-- <button class="btn btn_submit mr10 J_ajax_submit_btn" type="submit">导出PDF</button> -->



				</div>
			</div>
		</form>
	</div>
</block>